package com.wc.算法提高课.A第一章_动态规划.状态压缩DP.小国王;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/11 11:16
 * @description https://www.acwing.com/problem/content/description/1066/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 12, M = 1 << N, K = 110;
    // f[i][j][k] 表示前i行已经摆了j个国王状态为k的方案数
    static long[][][] f = new long[N][K][M];
    // 合法的状态
    static int[] state = new int[M];
    // 合法的状态转移,存的是state的下角标
    static int[][] head = new int[M][M];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 0; i < 1 << n; i++) {
            if (check(i)) state[++state[0]] = i;
        }
        // 相邻的可以转移的状态
        for (int i = 1; i <= state[0]; i++) {
            for (int j = 1; j <= state[0]; j++) {
                int a = state[i], b = state[j];
                if ((a & b) == 0 && check(a | b)) {
                    head[i][++head[i][0]] = j;
                }
            }
        }

        // 第0行0个国王状态是0的一种
        f[0][0][0] = 1;

        // 这里遍历到n + 1,是为了保证前面都算完了f[n + 1][k][0] = 上一行的全部方案数
        for (int i = 1; i <= n + 1; i++) {
            // 遍历国王数
            for (int j = 0; j <= m; j++) {
                // 当前行的状态为a
                for (int s = 1; s <= state[0]; s++) {
                    int a = state[s];
                    int c = count(a);
                    if (j >= c) {
                        // 上一行状态只能为b
                        for (int k = 1; k <= head[s][0]; k++) {
                            int b = state[head[s][k]];
                            f[i][j][a] += f[i - 1][j - c][b];
                        }
                    }
                }
            }
        }
        out.println(f[n + 1][m][0]);
        out.flush();
    }

    /**
     * 检查这个数是否有相邻的1
     *
     * @param x
     * @return
     */
    static boolean check(int x) {
        for (int i = 0; i < n; i++) {
            if ((x >> i & 1) == 1 && (x >> i + 1 & 1) == 1) {
                return false;
            }
        }
        return true;
    }

    static int count(int x) {
        int res = 0;
        for (int i = 0; i < n; i++) {
            res += x >> i & 1;
        }
        return res;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
